package com.hljx.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hljx.dto.DateDTO;
import com.hljx.entity.AssessmentCycle;
import com.hljx.entity.EtlItemImport;
import com.hljx.entity.SysDict;
import com.hljx.excel.ExcelTransfer;
import com.hljx.mapper.sys.EtlItemImportMapper;
import com.hljx.service.EtlItemImportService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hljx.vo.AccountingUnitsVO;
import com.hljx.vo.SysDictVO;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 数据抽取初步计算表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2023-11-30
 */
@Service
public class EtlItemImportServiceImpl extends ServiceImpl<EtlItemImportMapper, EtlItemImport> implements EtlItemImportService {

    @Autowired
    private ExcelTransfer<EtlItemImport> excelTransfer;

//    @Autowired
//    private ExcelTransfer<SysDict> dictExcelTransfer;




    @Override
    public void export(HttpServletResponse response) throws ClassNotFoundException {
        List<EtlItemImport> list = new ArrayList<>();
        excelTransfer.exportExcel(response, list, "手工导入", "sheet1", EtlItemImport.class);

    }

    @Override
    public void importExcel(MultipartFile file, HttpServletResponse response) throws ClassNotFoundException, IOException {
        excelTransfer.importExcel(file,this);
    }

    @Override
    public IPage<EtlItemImport> pageByPeriod(DateDTO dateDTO) {
        IPage page = page(dateDTO.getPage(), Wrappers.lambdaQuery(EtlItemImport.class)
                .eq(EtlItemImport::getPeriod, dateDTO.getPeriod())
                .eq(StringUtils.isNotBlank(dateDTO.getDeptCode()),EtlItemImport::getDeptCode,dateDTO.getDeptCode())
                .orderBy(true,true,EtlItemImport::getId));
        return page;
    }
}
